<template>
    <user-card-list-by-tags :user-list="userList" />
    <van-empty v-if="!userList || userList.length < 1" description="搜索结果为空" />
</template>

<script setup >
import {onMounted, ref} from 'vue';
import {useRoute} from "vue-router";
import myAxios from "../plugins/myAxios";
import {Toast} from "vant";
import qs from 'qs';
const loading = ref(true);
import UserCardListByTags from "../components/UserCardListByTags.vue";

const route = useRoute();
const {tags} = route.query;

const userList = ref([]);

onMounted(async () => {
    const userListData = await myAxios.get('/user/search/tags', {
        params: {
            tagNameList: tags
        },
        paramsSerializer: params => {
            return qs.stringify(params, {indices: false})
        }
    })
        .then(function (response) {
            console.log('/user/search/tags succeed', response);
            return response?.data;
        })
        .catch(function (error) {
            console.error('/user/search/tags error', error);
            Toast.fail('请求失败');
        })
    console.log(userListData)
    if (userListData) {
        userListData.forEach(user => {
            if (user.tags) {
                user.tags = JSON.parse(user.tags);
            }
        })
        userList.value = userListData;
    }
    loading.value = false;
})

/*const mockUser = {
  id: 123456,
  username: 'aka',
  profile: '秋殇别恋11111111111111111111111',
  userAccount: 'sadas',
  avatarUrl: 'https://xingqiu-tuchuang-1256524210.cos.ap-shanghai.myqcloud.com/3925/202209032140505.jpg',
  gender: 0,
  phone: '11111111111',
  email: 'aaaa@qq.com',
  userRole: 0,
  planetCode: '12',
  tags: ['java', 'emo', '学习中'],
  createTime: new Date(),
}*/


</script>

<style scoped>

</style>
